package com.menggudf.service.impl;

import com.menggudf.entity.FamilyHistory;
import com.menggudf.mapper.FamilyHistoryDao;
import com.menggudf.service.FamilyHistoryService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (FamilyHistory)表服务实现类
 *
 * @author makejava
 * @since 2025-02-20 16:58:28
 */
@Service("familyHistoryService")
public class FamilyHistoryServiceImpl implements FamilyHistoryService {
    @Resource
    private FamilyHistoryDao familyHistoryDao;

    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public FamilyHistory queryById(Integer fid) {
        return this.familyHistoryDao.queryById(fid);
    }

    /**
     * 分页查询
     *
     * @param familyHistory 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FamilyHistory> queryByPage(FamilyHistory familyHistory, PageRequest pageRequest) {
        long total = this.familyHistoryDao.count(familyHistory);
        return new PageImpl<>(this.familyHistoryDao.queryAllByLimit(familyHistory, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param familyHistory 实例对象
     * @return 实例对象
     */
    @Override
    public FamilyHistory insert(FamilyHistory familyHistory) {
        this.familyHistoryDao.insert(familyHistory);
        return familyHistory;
    }

    /**
     * 修改数据
     *
     * @param familyHistory 实例对象
     * @return 实例对象
     */
    @Override
    public FamilyHistory update(FamilyHistory familyHistory) {
        this.familyHistoryDao.update(familyHistory);
        return this.queryById(familyHistory.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer fid) {
        return this.familyHistoryDao.deleteById(fid) > 0;
    }
}
